package com.hx.er.action.admin.food;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.hx.er.action.base.ErAdminPageAction;
import com.hx.er.bean.detail.LabelDetailBean;
import com.hx.er.common.system.Constants;
import com.hx.er.common.system.ErLanguages;
import com.hx.er.common.system.ErProperties;
import com.hx.er.common.util.StringUtil;
import com.hx.er.service.admin.IAdminFoodService;

public class AdminLabelListAction extends ErAdminPageAction {
	// 序列化ID
	private static final long serialVersionUID = 4926512300151605899L;

	// 使用自定义页数，参见父类
	private int dataListLimit = Integer.parseInt(ErProperties.getProperty(Constants.PROPERTY_PIC_PAGE_SIZE));

	// 标签ID
	private long labelId;
	// 多语言标签名
	private String labelLang1;
	private String labelLang2;
	private String labelLang3;
	private String labelLang4;
	private String labelLang5;
	// 检索条件中的食品名
	private String labelText1;
	private String labelText2;
	private String labelText3;
	private String labelText4;
	private String labelText5;

	@Autowired
	private IAdminFoodService adminFoodService;

	private List<LabelDetailBean> labelDetailList;

	public String init() {
		// 初始化页面
		try {
			this.initPage();
		} catch (IOException e) {
			this.addActionError(super.getText(OPERATION_FAILURE_MSG));
			return INPUT;
		}

		return SUCCESS;
	}

	private void initPage() throws IOException {
		// 基本检索条件获取
		Map<String, Object> conditions = super.getConditionMap(dataListLimit);
		conditions.put("labelText1", StringUtil.EmptyToNull(this.labelText1));
		conditions.put("labelText2", StringUtil.EmptyToNull(this.labelText2));
		conditions.put("labelText3", StringUtil.EmptyToNull(this.labelText3));
		conditions.put("labelText4", StringUtil.EmptyToNull(this.labelText4));
		conditions.put("labelText5", StringUtil.EmptyToNull(this.labelText5));

		this.labelDetailList = this.adminFoodService.getLabelDetailAliveList(conditions);
		int labelDetailCount = this.adminFoodService.getLabelDetailAliveCount(conditions);

		super.pageCount = (int) Math.ceil(labelDetailCount / (double) super.dataListLimit);

		// 语言
		if (ErLanguages.getLangList().size() > 0) {
			this.labelLang1 = ErLanguages.getLocale(ErLanguages.getLangList().get(0).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 1) {
			this.labelLang2 = ErLanguages.getLocale(ErLanguages.getLangList().get(1).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 2) {
			this.labelLang3 = ErLanguages.getLocale(ErLanguages.getLangList().get(2).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 3) {
			this.labelLang4 = ErLanguages.getLocale(ErLanguages.getLangList().get(3).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 4) {
			this.labelLang5 = ErLanguages.getLocale(ErLanguages.getLangList().get(4).getLangId()).getLanguage().toUpperCase();
		}
	}

	public List<LabelDetailBean> getLabelDetailList() {
		return labelDetailList;
	}

	public void setLabelDetailList(List<LabelDetailBean> labelDetailList) {
		this.labelDetailList = labelDetailList;
	}

	public String getLabelLang1() {
		return labelLang1;
	}

	public String getLabelLang2() {
		return labelLang2;
	}

	public String getLabelLang3() {
		return labelLang3;
	}

	public String getLabelLang4() {
		return labelLang4;
	}

	public String getLabelLang5() {
		return labelLang5;
	}

	public String getLabelText1() {
		return labelText1;
	}

	public void setLabelText1(String labelText1) {
		this.labelText1 = labelText1;
	}

	public String getLabelText2() {
		return labelText2;
	}

	public void setLabelText2(String labelText2) {
		this.labelText2 = labelText2;
	}

	public String getLabelText3() {
		return labelText3;
	}

	public void setLabelText3(String labelText3) {
		this.labelText3 = labelText3;
	}

	public String getLabelText4() {
		return labelText4;
	}

	public void setLabelText4(String labelText4) {
		this.labelText4 = labelText4;
	}

	public String getLabelText5() {
		return labelText5;
	}

	public void setLabelText5(String labelText5) {
		this.labelText5 = labelText5;
	}

	public long getLabelId() {
		return labelId;
	}

	public void setLabelId(long labelId) {
		this.labelId = labelId;
	}

	public void setLabelLang1(String labelLang1) {
		this.labelLang1 = labelLang1;
	}

	public void setLabelLang2(String labelLang2) {
		this.labelLang2 = labelLang2;
	}

	public void setLabelLang3(String labelLang3) {
		this.labelLang3 = labelLang3;
	}

	public void setLabelLang4(String labelLang4) {
		this.labelLang4 = labelLang4;
	}

	public void setLabelLang5(String labelLang5) {
		this.labelLang5 = labelLang5;
	}

}
